package ObjectClass

class Counter {
  private var privateValue = 0

  def getPrivateValue(): Int = {
    privateValue
  }

  def setPrivateValue(privateValue: Int): Unit = {
    if (privateValue > 0) this.privateValue = privateValue
  }

  def increment(step: Int): Unit = {
    privateValue += step
  }

  def current(): Int = {
    privateValue
  }
}

class Counter02(var name: String)

class Counter03 {
  private var value = 0
  private var name = ""
  private var step = 1 //计算器的默认递进步长
  println("the main constructor")

  def this(name: String) { //第一个辅助构造器
    this() //调用主构造器
    this.name = name
    printf("the first auxiliary constructor,name:%s\n", name)
  }

  def this(name: String, step: Int) { //第二个辅助构造器
    this(name) //调用前一个辅助构造器
    this.step = step
    printf("the second auxiliary constructor,name:%s,step:%d\n", name, step)
  }

  def increment(step: Int): Unit = {
    value += step
  }

  def current(): Int = {
    value
  }
}
